package cn.waka.sys.admin.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.waka.sys.admin.object.AppVersion;

@Mapper
public interface AppVersionDao {
	int save(AppVersion version);
	List<AppVersion> findPage(@Param("appId")int appId,@Param("start")int start,@Param("size")int size);
	int findTotal(@Param("appId")int appId);
	
	@Insert("insert into s_version(apply,version,url,c_user,c_time,type,mark)values(#{appId},#{version},#{url},#{userId},#{createTime},#{type},#{mark})")
	int insert(AppVersion version);
	
	@Update("update s_version set version=#{version},url=#{url},c_user=#{userId},c_time=#{createTime},type=#{type},mark=#{mark} where id=#{id}")
	int update(AppVersion version);
	
	@Select("select apply as appId,version,url,c_user as userId,c_time as createTime,type,mark from s_version where id=#{id}")
	AppVersion getById(int id);
	
	@Delete("delete from s_version where id=#{id}")
	int del(int id);
	
	@Select("select count(1) from s_version where apply=#{appId} and version=#{version}")
	int findNewVersionExist(@Param("appId")int appId,@Param("version") String version);
	
	@Select("select count(1) from s_version where apply=#{appId} and version=#{newVersion} and version<>#{oldVersion}" )
	int findEditVersionExist(@Param("appId")int appId,@Param("oldVersion")String oldVersion,@Param("newVersion")String newVersion);
	
	Map<String,String> getMaxVersion(int appId);
}
